package com.lumingfeng.controller;


import javax.annotation.Resource;

import com.lumingfeng.entity.Goods;
import com.lumingfeng.entity.In;
import com.lumingfeng.entity.InDetail;
import com.lumingfeng.service.GoodsService;
import com.lumingfeng.service.InDetailService;
import com.lumingfeng.service.InService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.lumingfeng.entity.User;
import com.lumingfeng.service.IUserSerivice;

import java.util.List;

@RequestMapping("/user")
@Controller
public class UserController {

	@Resource(name="userService")
	private IUserSerivice userService;
	@Resource(name = "goodsService")
	private GoodsService goodsService;
	@Resource(name = "inService")
	private InService inService;
    @Resource(name = "inDetailService")
    private InDetailService inDetailService;

	@RequestMapping("/index")
	public ModelAndView index(){
		System.out.println("11");
		ModelAndView view =new ModelAndView("index");
		view.addObject("name", "lumingfeng");
		
		return view;
		
	}
	
	@RequestMapping("/test")
	public ModelAndView test(){
		Goods goods = goodsService.getGoodsById(1);
		System.out.println(goods);
		ModelAndView view =new ModelAndView("index");
		view.addObject("goods",goods);
		return view;
	}

    @RequestMapping("/add")
    public  ModelAndView add(){

        ModelAndView view =new ModelAndView("in_add");
        return view;
    }

    @RequestMapping("/save")
    public  ModelAndView save(Goods goods){

        System.out.print("goods:"+goods.toString());


        Integer result = goodsService.insertGoods(goods);

        if (result == 1) {
            ModelAndView view =new ModelAndView("in_list");
            view.addObject("inlist",goodsService.getGoods());
            return view;
        } else {
            return null;
        }
    }
}
